/*
 * Image.h
 *
 *  Created on: 15/01/2011
 *      Author: Nenem
 */

#ifndef IMAGE_H_
#define IMAGE_H_

#include <SDL/SDL.h>
#include <SDL/SDL_image.h>

#include <string>
#include <iostream>
using namespace std;

#include "Tools.h"
#include "Position.h"
#include "Direction.h"
//TODO everything
class Image {
private:
	SDL_Surface *image;
	SDL_Surface *imageAux;
	int w;
	int h;
	int x;
	int y;
	Point2D realPos;
	Point2D relPos;
	Point2D eastPI;
	Point2D westPI;
	Point2D northPI;
	Point2D southPI;
	int N_frames;
	int frameAtual;
	bool terrainApplied;
public:
	Image(){}
	Image(SDL_Surface *image, int w, int h, int N_frames, Point2D eastPI, Point2D westPI, Point2D northPI, Point2D southPI){
		x = 0;
		y = 0;
		this->N_frames = N_frames;
		frameAtual = 1;
		this->w = w;
		this->h = h;
		this->eastPI = eastPI;
		this->westPI = westPI;
		this->northPI = northPI;
		this->southPI = southPI;
		imageAux = image;
		this->image = SDL_ConvertSurface(imageAux, imageAux->format, imageAux->flags);
		terrainApplied = false;
	}
	Image(string imageName, int w, int h, int N_frames, Point2D eastPI, Point2D westPI, Point2D northPI, Point2D southPI){
		image = IMG_Load(imageName.c_str());
		if(!image){
			cout << SDL_GetError();
		}
		x = 0;
		y = 0;
		this->N_frames = N_frames;
		frameAtual = 1;
		this->w = w;
		this->h = h;
		this->eastPI = eastPI;
		this->westPI = westPI;
		this->northPI = northPI;
		this->southPI = southPI;
		this->image = image;
		imageAux = NULL;
		terrainApplied = false;
	}
	virtual ~Image();

	void aplyTerrain(SDL_Surface* terrain);
	void removeTerrain();
	void changeFrame();
	void resetFrame();
	void update(Direction *directio, Position *position);
	void loadSurface(string File);
	void freeSurface();
    bool getTerrainApplied() const;
    void setTerrainApplied(bool terrainApplied);

    Point2D getRealPos() const
    {
        return realPos;
    }

    void setRealPos(Point2D realPos)
    {
        this->realPos = realPos;
    }

    int getN_frames() const
    {
        return N_frames;
    }

    void setN_frames(int N_frames)
    {
        this->N_frames = N_frames;
    }

    int getFrameAtual() const
    {
        return frameAtual;
    }

    void setFrameAtual(int frameAtual)
    {
        this->frameAtual = frameAtual;
    }

    int getH() const
    {
        return h;
    }

    SDL_Surface *getImage() const
    {
        return image;
    }

    Point2D getRelPos() const
    {
        return relPos;
    }

    int getW() const
    {
        return w;
    }

    void setH(int h)
    {
        this->h = h;
    }

    void setImage(SDL_Surface *image)
    {
        this->image = image;
    }

    void setRelPos(Point2D relPos)
    {
        this->relPos = relPos;
    }

    void setW(int w)
    {
        this->w = w;
    }

    int getX() const
    {
        return x;
    }

    int getY() const
    {
        return y;
    }

    void setX(int x)
    {
        this->x = x;
    }

    void setY(int y)
    {
        this->y = y;
    }
};

#endif /* IMAGE_H_ */
